package com.hmall.item.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("item")
@Slf4j
public class ItemController {

    @Autowired
    private IItemService itemService;

    /**
     *    分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    public PageDTO listPage(int page,int size){

        PageDTO pageDTO = itemService.pageData(page, size);
        return pageDTO;

    }


    /**
     *  根据id 进行查询商品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Item item(@PathVariable Long id){
        return itemService.item(id);
    }

    /**
     *      商品的新增分类
     * @param item
     * @return
     */
    @PostMapping
    public void addItem(@RequestBody Item item){
        itemService.addItem(item);
    }

    /**
     *  根据 id 进行上架下架
     * @param id
     * @param status
     */
    @PutMapping("/status/{id}/{status}")
    public void itemStatus(@PathVariable Long id,@PathVariable Integer status){
        itemService.itemStatus(id,status);
    }

    /**
     *  更新操作
     * @param item
     */
    @PutMapping
    public void itemUpdata(@RequestBody Item item){
        itemService.itemUpdata(item);
    }

    /**
     *    根据id删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public void itemDelete(@PathVariable Long id){
        itemService.itemDelete(id);
    }

}
